package main

import (
	"awesomeProject/pkg/lesson4"
	"time"
)

func main() {
	//>>>>>>>>>>>>>>>>>>>>>lesson3<<<<<<<<<<<<<<<<<<<<<<<<
	//var source = "file" // 支持file、local、redis
	//t := time.Now().Unix()
	//key := "key" + strconv.FormatInt(t, 10)
	//var value interface{}
	//var err error
	//var store = getInstance(source)
	//// json文件写入
	//store.Set(key, t)
	//fmt.Printf("写入%s成功!key: %v, value: %v\n", source, key, t)
	//// json文件读取
	//value, err = store.Get(key)
	//if err != nil {
	//	log.Fatal(err)
	//}
	//fmt.Printf("读取来源：%s，读取%s: %v\n", source, key, value)
	//// json删除key
	//store.Delete(key)
	//fmt.Printf("删除%s成功!key: %v\n", source, key)
	//
	//source = "local"
	//// map内存写入
	//store = getInstance(source)
	//store.Set(key, t)
	//fmt.Printf("写入%s成功!key: %v, value: %v\n", source, key, t)
	//// map内存读取
	//value, err = store.Get(key)
	//if err != nil {
	//	log.Fatal(err)
	//}
	//fmt.Printf("读取来源：%s，读取%s: %v\n", source, key, value)
	//// map内存删除
	//store.Delete(key)
	//fmt.Printf("删除%s成功!key: %v\n", source, key)
	//
	//source = "redis"
	//store = getInstance(source)
	//pool.Init()
	//// redis写入
	//store.Set(key, t)
	//fmt.Printf("写入%s成功!key: %v, value: %v\n", source, key, t)
	//// redis读取
	//value, err = store.Get(key)
	//if err != nil {
	//	log.Fatal(err)
	//}
	//fmt.Printf("读取来源：%s，读取%s: %v\n", source, key, value)
	//// redis删除
	//store.Delete(key)
	//fmt.Printf("删除%s成功!key: %v\n", source, key)

	// lesson4
	const (
		cap = 100
	)
	var dq = lesson4.NewDataQueue(cap)
	// 启动多消费者
	go func(dq *lesson4.DataQueue) {
		for i := 0; i < 10; i++ {
			go func() {
				for {
					dq.Get()
				}
			}()
		}
	}(dq)
	// 启动多生产者
	go func(dq *lesson4.DataQueue) {
		for i := 0; i < 10; i++ {
			go func() {
				for {
					dq.Put("receive--")
				}
			}()
		}
	}(dq)
	time.Sleep(2 * time.Second)
}
